package com.cashmate.utilities;
/*
 * This class is for debugging purposes only..
 * Pass an object to toString Method (line 16)
 * then it will print out all properties of the object.
 * 
 */
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;

import java.util.ArrayList;
import java.util.List;

public class ClassUtils {

  private ClassUtils() {}

  public static String toString( Object o ) {
    ArrayList list = new ArrayList();
    ClassUtils.toString( o, o.getClass(), list );
    return o.getClass().getName().concat( list.toString() );
  }

  private static void toString( Object o, Class clazz, List list ) {
    Field f[] = clazz.getDeclaredFields();
    AccessibleObject.setAccessible( f, true );
    for ( int i = 0; i < f.length; i++ ) {
      try {
        list.add( f[i].getName() + "=" + f[i].get(o) );
      }
      catch ( IllegalAccessException e ) { e.printStackTrace(); }
      }
      if ( clazz.getSuperclass().getSuperclass() != null ) {
         toString( o, clazz.getSuperclass(), list );
      }
  }
}